package com.ruoyi.hr.controller.hr.attendempmanage.newempregister;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.hr.domain.Authority;
import com.ruoyi.hr.service.AuthorityService;
import com.ruoyi.hr.service.attendempmanage.newempregister.AttendNewEmpRegisterService;
import com.ruoyi.hr.util.BaseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * @author zeo
 * @explain 新员工登记
 * @date 2020/3/13
 */
@Controller
@RequestMapping("/attendEmpManage/NewEmpRegister")
public class NewEmpRegisterController extends BaseController {

    @Autowired
    AttendNewEmpRegisterService attendNewEmpRegisterService;

    @Autowired
    AuthorityService authorityService;

    private String prefix = "hr/attendempmanage/newempregister";

    /**
     * 跳转分页页面
     */
    @GetMapping()
    public String attendNewEmpRegister() {
        return prefix + "/newEmpRegister";
    }

    @RequestMapping("/findAttendNewEmpRegister")
    @ResponseBody
    public TableDataInfo findAttendNewEmpRegister(@RequestParam Map map) {
        Authority authority = authorityService.findAuthorAndIsAdmin();
        startPage();
        return getDataTable(attendNewEmpRegisterService.findAttendNewEmpRegister(map, authority));
    }

    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") String id, ModelMap mmap) {
        //取轮班组
        mmap.put("group",attendNewEmpRegisterService.findGroup());
        mmap.put("attendNewEmpRegister", attendNewEmpRegisterService.findAttendNewEmpRegisterById(id));
        return prefix + "/editNewEmpRegister";
    }

    @RequestMapping("/edit")
    @ResponseBody
    public AjaxResult edit(@RequestParam Map map){
        return toAjax(attendNewEmpRegisterService.edit(map));
    }

    /**
     * 数据确认,取消确认,执行
     */
    @PostMapping("/procedure")
    @ResponseBody
    public BaseResult procedure(String allId, String procedure) {
        return attendNewEmpRegisterService.procedure(allId, procedure);
    }

    @GetMapping("/history")
    public String attendNewEmpHistory() {
        return prefix + "/newEmpHistory";
    }

    @RequestMapping("/history")
    @ResponseBody
    public TableDataInfo attendNewEmpHistory(@RequestParam Map map) {
        return getDataTable(attendNewEmpRegisterService.findAttendNewEmpHistory(map));
    }

}
